/**************************************************************************
*   Copyright (C) 2009 Chernov Dmitry                                     *
*   diman4ik.chernov@gmail.com                                            *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/

#ifndef KORNERS_PROTOCOL
#define KORNERS_PROTOCOL

#include <QVector>
#include <QVariant>


class KornersMessage
{
public:
    enum MessageType
    {
        handshake_s = 1,
        handshake_c = 2,
        move = 3,
        regret = 4,
    };

    int type;
    QVector<QVariant> data;
};

class KornersProtocol : public QObject
{
    Q_OBJECT
public:
    KornersProtocol( QObject* parent = 0 ) : QObject( parent ) {}
    virtual ~KornersProtocol() {}
    virtual void processMessage( const QByteArray& ) = 0;
    virtual const QByteArray& start() = 0;
    virtual const QByteArray& stop() = 0;
    virtual const QByteArray& move( const QPoint& src, const QPoint& dst ) = 0;
public slots:
signals:
    void messageParsed( KornersMessage mess );
};


class KornersGameProtocol : public KornersProtocol
{
    Q_OBJECT
public:
    explicit KornersGameProtocol( const QString& name, bool server );
    ~KornersGameProtocol() {}
    void processMessage( const QByteArray& );
    const QByteArray& move( const QPoint& src, const QPoint& dst );
    const QByteArray& start();
    const QByteArray& stop();

private:
    int m_version;
    bool m_server;
    QString m_playerName;
};

#endif